{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.None   2.[30,4]   3.3    4.97"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.false  2.true  3.false  4.true"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入字符串'1231456'\n",
      "Counter({\"'\": 2, '1': 2, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1})\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "x = input(\"请输入字符串\")\n",
    "frequencies = Counter(x)\n",
    "print(frequencies)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'1,2,3,6,5,4,5,2,3,6'\n"
     ]
    }
   ],
   "source": [
    "s =eval( input('请输入一个字符串：'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('1', 0), ('4', 10)]\n"
     ]
    }
   ],
   "source": [
    "positions = [(ch,index)for index ,ch in enumerate(s)if s.index(ch)==s.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'12156454654'\n",
      "[('2', 1), ('1', 2), ('6', 8), ('5', 9), ('4', 10)]\n"
     ]
    }
   ],
   "source": [
    "x = eval(input('请输入一个字符串'))\n",
    "positions =[(ch,index) for index,ch in enumerate(x)\n",
    "if index == x.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表：[{3,54,5,},{1,5,6}]\n",
      "{1, 3, 5, 54, 6}\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "from operator import __or__\n",
    "x = eval(input('请输入包含若干集合的列表：'))\n",
    "print(reduce(__or__,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'1,2,3,6,5,4'\n",
      "No\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串'))\n",
    "x = s[::-1]\n",
    "if s == x:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "书上：1.可迭代对象   2.false   3.None   4.remove()   5.[6, 7, 9, 11]    6.{} '键' '值' '键'  7.items(),  keys(),  values()  \n",
    "8.dict = {i:x for i in a for x in b} print(dict)   9.b=a[::3]  10.[5 for i in range(10)]  11.不可以  \n",
    "12.from collections import Counter    \n",
    "data = ['dasd','aaabbb','ggggghhhhhh']\n",
    "for d in data:\n",
    "    res=Counter(d)\n",
    "    max_len=0\n",
    "    for key in res:\n",
    "        if max_len<res[key]:\n",
    "            max_len=res[key]\n",
    "    n=len(d)\n",
    "    if max_len>n/2:\n",
    "        data.remove(d)\n",
    "print(data)\n",
    "13.                14.当列表从中间或从头增加或删除元素时,列表对象自动进行内存扩展或收缩,从而保证元素之间没有缝隙,但这涉及到列表元素的大量的移动,效率较低,应尽量从列表尾部进行元素的增加与删除操作以提高处理速度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[67, 91, 99, 38, 5, 90, 31, 77, 11, 14, 13, 61, 6, 72, 88, 25, 43, 16, 0, 23, 42, 45, 56, 21, 28, 48, 24, 28, 47, 6, 57, 92, 20, 60, 67, 52, 24, 31, 16, 25, 10, 5, 40, 2, 5, 45, 45, 79, 69, 1, 71, 35, 22, 40, 95, 83, 46, 78, 53, 84, 24, 27, 55, 13, 40, 51, 83, 78, 63, 22, 23, 49, 58, 69, 72, 83, 95, 61, 24, 58, 17, 33, 71, 99, 46, 38, 7, 61, 68, 95, 60, 24, 32, 53, 85, 94, 8, 70, 54, 82, 45, 97, 82, 80, 52, 53, 60, 74, 95, 1, 89, 50, 24, 38, 88, 52, 67, 13, 8, 1, 41, 91, 84, 6, 2, 7, 100, 33, 100, 97, 74, 76, 94, 51, 23, 35, 4, 75, 43, 15, 16, 56, 0, 30, 70, 51, 77, 65, 31, 30, 44, 70, 25, 21, 14, 74, 17, 19, 9, 40, 58, 88, 23, 38, 2, 49, 32, 94, 45, 15, 36, 53, 15, 88, 83, 89, 55, 67, 95, 26, 89, 59, 66, 9, 35, 58, 97, 64, 65, 82, 75, 2, 17, 26, 72, 50, 8, 48, 77, 63, 62, 33, 70, 57, 27, 21, 26, 56, 48, 22, 38, 27, 42, 51, 68, 56, 50, 10, 41, 74, 95, 1, 29, 79, 93, 86, 41, 17, 3, 38, 19, 87, 80, 57, 21, 11, 93, 90, 94, 19, 47, 99, 99, 29, 11, 17, 4, 4, 30, 44, 96, 94, 65, 3, 22, 58, 39, 35, 100, 43, 1, 26, 59, 61, 42, 59, 12, 6, 48, 43, 45, 62, 45, 30, 13, 62, 88, 31, 83, 10, 86, 58, 38, 27, 54, 34, 97, 11, 0, 78, 1, 27, 75, 2, 91, 3, 29, 69, 72, 28, 11, 9, 5, 83, 89, 51, 16, 28, 1, 43, 55, 30, 92, 3, 44, 95, 10, 40, 69, 67, 73, 51, 5, 61, 98, 63, 1, 75, 54, 29, 2, 54, 4, 5, 73, 37, 3, 6, 76, 74, 48, 71, 30, 26, 48, 68, 16, 96, 65, 57, 39, 83, 26, 44, 46, 8, 38, 53, 31, 46, 76, 40, 14, 21, 15, 88, 90, 32, 21, 26, 49, 96, 57, 89, 27, 10, 82, 83, 56, 65, 62, 35, 2, 13, 62, 35, 72, 52, 5, 99, 53, 60, 30, 20, 82, 38, 10, 33, 83, 47, 34, 88, 79, 20, 10, 4, 94, 71, 61, 9, 64, 32, 81, 93, 17, 47, 86, 31, 15, 91, 92, 30, 87, 87, 79, 5, 21, 38, 54, 76, 9, 66, 98, 98, 83, 93, 77, 99, 97, 10, 24, 42, 52, 45, 13, 45, 10, 63, 99, 5, 77, 14, 4, 32, 77, 92, 45, 45, 83, 97, 46, 0, 30, 30, 89, 7, 97, 2, 63, 28, 16, 25, 27, 97, 61, 56, 3, 90, 63, 84, 72, 37, 60, 4, 21, 20, 86, 51, 21, 93, 9, 99, 30, 48, 61, 85, 60, 26, 85, 90, 100, 23, 14, 93, 74, 92, 14, 73, 2, 68, 95, 81, 24, 49, 53, 43, 41, 90, 89, 63, 18, 43, 39, 54, 63, 21, 4, 51, 93, 69, 31, 83, 27, 22, 47, 95, 84, 38, 2, 47, 92, 4, 23, 20, 23, 28, 51, 16, 99, 19, 79, 94, 46, 37, 17, 24, 40, 45, 81, 66, 97, 76, 50, 24, 39, 24, 57, 45, 44, 31, 87, 51, 50, 71, 93, 65, 26, 3, 15, 90, 68, 54, 92, 89, 20, 8, 9, 84, 78, 53, 79, 27, 81, 27, 74, 9, 79, 88, 38, 26, 99, 94, 36, 66, 61, 89, 54, 87, 92, 39, 26, 39, 37, 22, 100, 16, 87, 44, 64, 68, 28, 89, 53, 87, 85, 39, 79, 17, 90, 83, 37, 14, 25, 71, 21, 82, 22, 24, 51, 66, 50, 66, 50, 63, 73, 2, 76, 75, 69, 98, 80, 59, 76, 91, 15, 89, 82, 76, 72, 15, 76, 53, 82, 57, 46, 68, 82, 13, 26, 29, 32, 8, 5, 49, 32, 70, 50, 27, 99, 14, 3, 97, 83, 1, 75, 76, 71, 36, 10, 38, 52, 50, 10, 66, 31, 21, 44, 38, 21, 9, 94, 44, 49, 69, 1, 14, 94, 0, 83, 73, 75, 19, 18, 60, 76, 10, 63, 73, 43, 66, 13, 10, 69, 66, 47, 53, 41, 88, 75, 0, 17, 52, 56, 45, 24, 47, 39, 98, 13, 53, 43, 76, 62, 78, 10, 93, 36, 89, 10, 80, 2, 13, 90, 92, 34, 13, 27, 11, 100, 56, 80, 65, 20, 95, 75, 64, 90, 16, 43, 61, 59, 13, 93, 87, 87, 77, 59, 63, 17, 53, 5, 10, 91, 67, 97, 88, 5, 11, 31, 46, 72, 28, 69, 90, 34, 38, 23, 55, 76, 41, 24, 15, 24, 68, 22, 89, 35, 36, 38, 76, 50, 52, 5, 98, 16, 19, 38, 93, 49, 93, 38, 69, 80, 27, 68, 39, 10, 36, 43, 23, 39, 71, 95, 63, 83, 1, 18, 49, 30, 23, 2, 14, 97, 97, 36, 75, 97, 0, 23, 7, 66, 77, 29, 30, 47, 34, 27, 11, 10, 71, 80, 95, 59, 14, 46, 94, 48, 5, 21, 12, 83, 65, 5, 43, 98, 81, 51, 41, 72, 26, 21, 93, 95, 75, 32, 25, 80, 27, 85, 93, 93, 92, 4, 2, 95, 43, 54, 96, 59, 45, 59, 68, 20, 25, 81, 69, 51, 93, 86, 76, 43, 32, 24, 43, 41, 43, 12, 90, 26, 90, 61, 38, 53, 94, 94, 29, 52, 36, 64, 29, 42, 14, 92, 30, 81, 96, 97, 14, 94, 93, 18, 10, 2, 78, 13, 20, 30, 3, 65, 26, 79, 78, 64, 25, 5, 57, 74, 24, 71, 10, 39, 15, 5, 96, 88, 49, 12, 76, 38, 29, 96, 16, 44, 60, 21, 24, 89, 29, 7, 30, 55, 85, 100, 65, 97, 41, 71, 43, 15, 24, 0, 91, 80, 69, 100, 90, 54, 71, 71, 98]\n",
      "67 : 6\n",
      "91 : 7\n",
      "99 : 11\n",
      "38 : 20\n",
      "5 : 17\n",
      "90 : 14\n",
      "31 : 10\n",
      "77 : 8\n",
      "11 : 8\n",
      "14 : 13\n",
      "13 : 13\n",
      "61 : 11\n",
      "6 : 5\n",
      "72 : 9\n",
      "88 : 11\n",
      "25 : 8\n",
      "43 : 17\n",
      "16 : 11\n",
      "0 : 8\n",
      "23 : 11\n",
      "42 : 5\n",
      "45 : 15\n",
      "56 : 8\n",
      "21 : 16\n",
      "28 : 8\n",
      "48 : 8\n",
      "24 : 19\n",
      "28 : 8\n",
      "47 : 9\n",
      "6 : 5\n",
      "57 : 8\n",
      "92 : 11\n",
      "20 : 9\n",
      "60 : 8\n",
      "67 : 6\n",
      "52 : 9\n",
      "24 : 19\n",
      "31 : 10\n",
      "16 : 11\n",
      "25 : 8\n",
      "10 : 20\n",
      "5 : 17\n",
      "40 : 7\n",
      "2 : 15\n",
      "5 : 17\n",
      "45 : 15\n",
      "45 : 15\n",
      "79 : 9\n",
      "69 : 12\n",
      "1 : 11\n",
      "71 : 13\n",
      "35 : 7\n",
      "22 : 8\n",
      "40 : 7\n",
      "95 : 14\n",
      "83 : 17\n",
      "46 : 9\n",
      "78 : 7\n",
      "53 : 14\n",
      "84 : 5\n",
      "24 : 19\n",
      "27 : 15\n",
      "55 : 5\n",
      "13 : 13\n",
      "40 : 7\n",
      "51 : 13\n",
      "83 : 17\n",
      "78 : 7\n",
      "63 : 12\n",
      "22 : 8\n",
      "23 : 11\n",
      "49 : 9\n",
      "58 : 6\n",
      "69 : 12\n",
      "72 : 9\n",
      "83 : 17\n",
      "95 : 14\n",
      "61 : 11\n",
      "24 : 19\n",
      "58 : 6\n",
      "17 : 10\n",
      "33 : 4\n",
      "71 : 13\n",
      "99 : 11\n",
      "46 : 9\n",
      "38 : 20\n",
      "7 : 5\n",
      "61 : 11\n",
      "68 : 10\n",
      "95 : 14\n",
      "60 : 8\n",
      "24 : 19\n",
      "32 : 9\n",
      "53 : 14\n",
      "85 : 6\n",
      "94 : 14\n",
      "8 : 6\n",
      "70 : 5\n",
      "54 : 10\n",
      "82 : 9\n",
      "45 : 15\n",
      "97 : 16\n",
      "82 : 9\n",
      "80 : 9\n",
      "52 : 9\n",
      "53 : 14\n",
      "60 : 8\n",
      "74 : 8\n",
      "95 : 14\n",
      "1 : 11\n",
      "89 : 14\n",
      "50 : 10\n",
      "24 : 19\n",
      "38 : 20\n",
      "88 : 11\n",
      "52 : 9\n",
      "67 : 6\n",
      "13 : 13\n",
      "8 : 6\n",
      "1 : 11\n",
      "41 : 9\n",
      "91 : 7\n",
      "84 : 5\n",
      "6 : 5\n",
      "2 : 15\n",
      "7 : 5\n",
      "100 : 8\n",
      "33 : 4\n",
      "100 : 8\n",
      "97 : 16\n",
      "74 : 8\n",
      "76 : 16\n",
      "94 : 14\n",
      "51 : 13\n",
      "23 : 11\n",
      "35 : 7\n",
      "4 : 10\n",
      "75 : 11\n",
      "43 : 17\n",
      "15 : 11\n",
      "16 : 11\n",
      "56 : 8\n",
      "0 : 8\n",
      "30 : 16\n",
      "70 : 5\n",
      "51 : 13\n",
      "77 : 8\n",
      "65 : 10\n",
      "31 : 10\n",
      "30 : 16\n",
      "44 : 9\n",
      "70 : 5\n",
      "25 : 8\n",
      "21 : 16\n",
      "14 : 13\n",
      "74 : 8\n",
      "17 : 10\n",
      "19 : 6\n",
      "9 : 9\n",
      "40 : 7\n",
      "58 : 6\n",
      "88 : 11\n",
      "23 : 11\n",
      "38 : 20\n",
      "2 : 15\n",
      "49 : 9\n",
      "32 : 9\n",
      "94 : 14\n",
      "45 : 15\n",
      "15 : 11\n",
      "36 : 8\n",
      "53 : 14\n",
      "15 : 11\n",
      "88 : 11\n",
      "83 : 17\n",
      "89 : 14\n",
      "55 : 5\n",
      "67 : 6\n",
      "95 : 14\n",
      "26 : 15\n",
      "89 : 14\n",
      "59 : 9\n",
      "66 : 10\n",
      "9 : 9\n",
      "35 : 7\n",
      "58 : 6\n",
      "97 : 16\n",
      "64 : 6\n",
      "65 : 10\n",
      "82 : 9\n",
      "75 : 11\n",
      "2 : 15\n",
      "17 : 10\n",
      "26 : 15\n",
      "72 : 9\n",
      "50 : 10\n",
      "8 : 6\n",
      "48 : 8\n",
      "77 : 8\n",
      "63 : 12\n",
      "62 : 6\n",
      "33 : 4\n",
      "70 : 5\n",
      "57 : 8\n",
      "27 : 15\n",
      "21 : 16\n",
      "26 : 15\n",
      "56 : 8\n",
      "48 : 8\n",
      "22 : 8\n",
      "38 : 20\n",
      "27 : 15\n",
      "42 : 5\n",
      "51 : 13\n",
      "68 : 10\n",
      "56 : 8\n",
      "50 : 10\n",
      "10 : 20\n",
      "41 : 9\n",
      "74 : 8\n",
      "95 : 14\n",
      "1 : 11\n",
      "29 : 10\n",
      "79 : 9\n",
      "93 : 17\n",
      "86 : 5\n",
      "41 : 9\n",
      "17 : 10\n",
      "3 : 9\n",
      "38 : 20\n",
      "19 : 6\n",
      "87 : 9\n",
      "80 : 9\n",
      "57 : 8\n",
      "21 : 16\n",
      "11 : 8\n",
      "93 : 17\n",
      "90 : 14\n",
      "94 : 14\n",
      "19 : 6\n",
      "47 : 9\n",
      "99 : 11\n",
      "99 : 11\n",
      "29 : 10\n",
      "11 : 8\n",
      "17 : 10\n",
      "4 : 10\n",
      "4 : 10\n",
      "30 : 16\n",
      "44 : 9\n",
      "96 : 7\n",
      "94 : 14\n",
      "65 : 10\n",
      "3 : 9\n",
      "22 : 8\n",
      "58 : 6\n",
      "39 : 11\n",
      "35 : 7\n",
      "100 : 8\n",
      "43 : 17\n",
      "1 : 11\n",
      "26 : 15\n",
      "59 : 9\n",
      "61 : 11\n",
      "42 : 5\n",
      "59 : 9\n",
      "12 : 4\n",
      "6 : 5\n",
      "48 : 8\n",
      "43 : 17\n",
      "45 : 15\n",
      "62 : 6\n",
      "45 : 15\n",
      "30 : 16\n",
      "13 : 13\n",
      "62 : 6\n",
      "88 : 11\n",
      "31 : 10\n",
      "83 : 17\n",
      "10 : 20\n",
      "86 : 5\n",
      "58 : 6\n",
      "38 : 20\n",
      "27 : 15\n",
      "54 : 10\n",
      "34 : 5\n",
      "97 : 16\n",
      "11 : 8\n",
      "0 : 8\n",
      "78 : 7\n",
      "1 : 11\n",
      "27 : 15\n",
      "75 : 11\n",
      "2 : 15\n",
      "91 : 7\n",
      "3 : 9\n",
      "29 : 10\n",
      "69 : 12\n",
      "72 : 9\n",
      "28 : 8\n",
      "11 : 8\n",
      "9 : 9\n",
      "5 : 17\n",
      "83 : 17\n",
      "89 : 14\n",
      "51 : 13\n",
      "16 : 11\n",
      "28 : 8\n",
      "1 : 11\n",
      "43 : 17\n",
      "55 : 5\n",
      "30 : 16\n",
      "92 : 11\n",
      "3 : 9\n",
      "44 : 9\n",
      "95 : 14\n",
      "10 : 20\n",
      "40 : 7\n",
      "69 : 12\n",
      "67 : 6\n",
      "73 : 6\n",
      "51 : 13\n",
      "5 : 17\n",
      "61 : 11\n",
      "98 : 8\n",
      "63 : 12\n",
      "1 : 11\n",
      "75 : 11\n",
      "54 : 10\n",
      "29 : 10\n",
      "2 : 15\n",
      "54 : 10\n",
      "4 : 10\n",
      "5 : 17\n",
      "73 : 6\n",
      "37 : 5\n",
      "3 : 9\n",
      "6 : 5\n",
      "76 : 16\n",
      "74 : 8\n",
      "48 : 8\n",
      "71 : 13\n",
      "30 : 16\n",
      "26 : 15\n",
      "48 : 8\n",
      "68 : 10\n",
      "16 : 11\n",
      "96 : 7\n",
      "65 : 10\n",
      "57 : 8\n",
      "39 : 11\n",
      "83 : 17\n",
      "26 : 15\n",
      "44 : 9\n",
      "46 : 9\n",
      "8 : 6\n",
      "38 : 20\n",
      "53 : 14\n",
      "31 : 10\n",
      "46 : 9\n",
      "76 : 16\n",
      "40 : 7\n",
      "14 : 13\n",
      "21 : 16\n",
      "15 : 11\n",
      "88 : 11\n",
      "90 : 14\n",
      "32 : 9\n",
      "21 : 16\n",
      "26 : 15\n",
      "49 : 9\n",
      "96 : 7\n",
      "57 : 8\n",
      "89 : 14\n",
      "27 : 15\n",
      "10 : 20\n",
      "82 : 9\n",
      "83 : 17\n",
      "56 : 8\n",
      "65 : 10\n",
      "62 : 6\n",
      "35 : 7\n",
      "2 : 15\n",
      "13 : 13\n",
      "62 : 6\n",
      "35 : 7\n",
      "72 : 9\n",
      "52 : 9\n",
      "5 : 17\n",
      "99 : 11\n",
      "53 : 14\n",
      "60 : 8\n",
      "30 : 16\n",
      "20 : 9\n",
      "82 : 9\n",
      "38 : 20\n",
      "10 : 20\n",
      "33 : 4\n",
      "83 : 17\n",
      "47 : 9\n",
      "34 : 5\n",
      "88 : 11\n",
      "79 : 9\n",
      "20 : 9\n",
      "10 : 20\n",
      "4 : 10\n",
      "94 : 14\n",
      "71 : 13\n",
      "61 : 11\n",
      "9 : 9\n",
      "64 : 6\n",
      "32 : 9\n",
      "81 : 7\n",
      "93 : 17\n",
      "17 : 10\n",
      "47 : 9\n",
      "86 : 5\n",
      "31 : 10\n",
      "15 : 11\n",
      "91 : 7\n",
      "92 : 11\n",
      "30 : 16\n",
      "87 : 9\n",
      "87 : 9\n",
      "79 : 9\n",
      "5 : 17\n",
      "21 : 16\n",
      "38 : 20\n",
      "54 : 10\n",
      "76 : 16\n",
      "9 : 9\n",
      "66 : 10\n",
      "98 : 8\n",
      "98 : 8\n",
      "83 : 17\n",
      "93 : 17\n",
      "77 : 8\n",
      "99 : 11\n",
      "97 : 16\n",
      "10 : 20\n",
      "24 : 19\n",
      "42 : 5\n",
      "52 : 9\n",
      "45 : 15\n",
      "13 : 13\n",
      "45 : 15\n",
      "10 : 20\n",
      "63 : 12\n",
      "99 : 11\n",
      "5 : 17\n",
      "77 : 8\n",
      "14 : 13\n",
      "4 : 10\n",
      "32 : 9\n",
      "77 : 8\n",
      "92 : 11\n",
      "45 : 15\n",
      "45 : 15\n",
      "83 : 17\n",
      "97 : 16\n",
      "46 : 9\n",
      "0 : 8\n",
      "30 : 16\n",
      "30 : 16\n",
      "89 : 14\n",
      "7 : 5\n",
      "97 : 16\n",
      "2 : 15\n",
      "63 : 12\n",
      "28 : 8\n",
      "16 : 11\n",
      "25 : 8\n",
      "27 : 15\n",
      "97 : 16\n",
      "61 : 11\n",
      "56 : 8\n",
      "3 : 9\n",
      "90 : 14\n",
      "63 : 12\n",
      "84 : 5\n",
      "72 : 9\n",
      "37 : 5\n",
      "60 : 8\n",
      "4 : 10\n",
      "21 : 16\n",
      "20 : 9\n",
      "86 : 5\n",
      "51 : 13\n",
      "21 : 16\n",
      "93 : 17\n",
      "9 : 9\n",
      "99 : 11\n",
      "30 : 16\n",
      "48 : 8\n",
      "61 : 11\n",
      "85 : 6\n",
      "60 : 8\n",
      "26 : 15\n",
      "85 : 6\n",
      "90 : 14\n",
      "100 : 8\n",
      "23 : 11\n",
      "14 : 13\n",
      "93 : 17\n",
      "74 : 8\n",
      "92 : 11\n",
      "14 : 13\n",
      "73 : 6\n",
      "2 : 15\n",
      "68 : 10\n",
      "95 : 14\n",
      "81 : 7\n",
      "24 : 19\n",
      "49 : 9\n",
      "53 : 14\n",
      "43 : 17\n",
      "41 : 9\n",
      "90 : 14\n",
      "89 : 14\n",
      "63 : 12\n",
      "18 : 4\n",
      "43 : 17\n",
      "39 : 11\n",
      "54 : 10\n",
      "63 : 12\n",
      "21 : 16\n",
      "4 : 10\n",
      "51 : 13\n",
      "93 : 17\n",
      "69 : 12\n",
      "31 : 10\n",
      "83 : 17\n",
      "27 : 15\n",
      "22 : 8\n",
      "47 : 9\n",
      "95 : 14\n",
      "84 : 5\n",
      "38 : 20\n",
      "2 : 15\n",
      "47 : 9\n",
      "92 : 11\n",
      "4 : 10\n",
      "23 : 11\n",
      "20 : 9\n",
      "23 : 11\n",
      "28 : 8\n",
      "51 : 13\n",
      "16 : 11\n",
      "99 : 11\n",
      "19 : 6\n",
      "79 : 9\n",
      "94 : 14\n",
      "46 : 9\n",
      "37 : 5\n",
      "17 : 10\n",
      "24 : 19\n",
      "40 : 7\n",
      "45 : 15\n",
      "81 : 7\n",
      "66 : 10\n",
      "97 : 16\n",
      "76 : 16\n",
      "50 : 10\n",
      "24 : 19\n",
      "39 : 11\n",
      "24 : 19\n",
      "57 : 8\n",
      "45 : 15\n",
      "44 : 9\n",
      "31 : 10\n",
      "87 : 9\n",
      "51 : 13\n",
      "50 : 10\n",
      "71 : 13\n",
      "93 : 17\n",
      "65 : 10\n",
      "26 : 15\n",
      "3 : 9\n",
      "15 : 11\n",
      "90 : 14\n",
      "68 : 10\n",
      "54 : 10\n",
      "92 : 11\n",
      "89 : 14\n",
      "20 : 9\n",
      "8 : 6\n",
      "9 : 9\n",
      "84 : 5\n",
      "78 : 7\n",
      "53 : 14\n",
      "79 : 9\n",
      "27 : 15\n",
      "81 : 7\n",
      "27 : 15\n",
      "74 : 8\n",
      "9 : 9\n",
      "79 : 9\n",
      "88 : 11\n",
      "38 : 20\n",
      "26 : 15\n",
      "99 : 11\n",
      "94 : 14\n",
      "36 : 8\n",
      "66 : 10\n",
      "61 : 11\n",
      "89 : 14\n",
      "54 : 10\n",
      "87 : 9\n",
      "92 : 11\n",
      "39 : 11\n",
      "26 : 15\n",
      "39 : 11\n",
      "37 : 5\n",
      "22 : 8\n",
      "100 : 8\n",
      "16 : 11\n",
      "87 : 9\n",
      "44 : 9\n",
      "64 : 6\n",
      "68 : 10\n",
      "28 : 8\n",
      "89 : 14\n",
      "53 : 14\n",
      "87 : 9\n",
      "85 : 6\n",
      "39 : 11\n",
      "79 : 9\n",
      "17 : 10\n",
      "90 : 14\n",
      "83 : 17\n",
      "37 : 5\n",
      "14 : 13\n",
      "25 : 8\n",
      "71 : 13\n",
      "21 : 16\n",
      "82 : 9\n",
      "22 : 8\n",
      "24 : 19\n",
      "51 : 13\n",
      "66 : 10\n",
      "50 : 10\n",
      "66 : 10\n",
      "50 : 10\n",
      "63 : 12\n",
      "73 : 6\n",
      "2 : 15\n",
      "76 : 16\n",
      "75 : 11\n",
      "69 : 12\n",
      "98 : 8\n",
      "80 : 9\n",
      "59 : 9\n",
      "76 : 16\n",
      "91 : 7\n",
      "15 : 11\n",
      "89 : 14\n",
      "82 : 9\n",
      "76 : 16\n",
      "72 : 9\n",
      "15 : 11\n",
      "76 : 16\n",
      "53 : 14\n",
      "82 : 9\n",
      "57 : 8\n",
      "46 : 9\n",
      "68 : 10\n",
      "82 : 9\n",
      "13 : 13\n",
      "26 : 15\n",
      "29 : 10\n",
      "32 : 9\n",
      "8 : 6\n",
      "5 : 17\n",
      "49 : 9\n",
      "32 : 9\n",
      "70 : 5\n",
      "50 : 10\n",
      "27 : 15\n",
      "99 : 11\n",
      "14 : 13\n",
      "3 : 9\n",
      "97 : 16\n",
      "83 : 17\n",
      "1 : 11\n",
      "75 : 11\n",
      "76 : 16\n",
      "71 : 13\n",
      "36 : 8\n",
      "10 : 20\n",
      "38 : 20\n",
      "52 : 9\n",
      "50 : 10\n",
      "10 : 20\n",
      "66 : 10\n",
      "31 : 10\n",
      "21 : 16\n",
      "44 : 9\n",
      "38 : 20\n",
      "21 : 16\n",
      "9 : 9\n",
      "94 : 14\n",
      "44 : 9\n",
      "49 : 9\n",
      "69 : 12\n",
      "1 : 11\n",
      "14 : 13\n",
      "94 : 14\n",
      "0 : 8\n",
      "83 : 17\n",
      "73 : 6\n",
      "75 : 11\n",
      "19 : 6\n",
      "18 : 4\n",
      "60 : 8\n",
      "76 : 16\n",
      "10 : 20\n",
      "63 : 12\n",
      "73 : 6\n",
      "43 : 17\n",
      "66 : 10\n",
      "13 : 13\n",
      "10 : 20\n",
      "69 : 12\n",
      "66 : 10\n",
      "47 : 9\n",
      "53 : 14\n",
      "41 : 9\n",
      "88 : 11\n",
      "75 : 11\n",
      "0 : 8\n",
      "17 : 10\n",
      "52 : 9\n",
      "56 : 8\n",
      "45 : 15\n",
      "24 : 19\n",
      "47 : 9\n",
      "39 : 11\n",
      "98 : 8\n",
      "13 : 13\n",
      "53 : 14\n",
      "43 : 17\n",
      "76 : 16\n",
      "62 : 6\n",
      "78 : 7\n",
      "10 : 20\n",
      "93 : 17\n",
      "36 : 8\n",
      "89 : 14\n",
      "10 : 20\n",
      "80 : 9\n",
      "2 : 15\n",
      "13 : 13\n",
      "90 : 14\n",
      "92 : 11\n",
      "34 : 5\n",
      "13 : 13\n",
      "27 : 15\n",
      "11 : 8\n",
      "100 : 8\n",
      "56 : 8\n",
      "80 : 9\n",
      "65 : 10\n",
      "20 : 9\n",
      "95 : 14\n",
      "75 : 11\n",
      "64 : 6\n",
      "90 : 14\n",
      "16 : 11\n",
      "43 : 17\n",
      "61 : 11\n",
      "59 : 9\n",
      "13 : 13\n",
      "93 : 17\n",
      "87 : 9\n",
      "87 : 9\n",
      "77 : 8\n",
      "59 : 9\n",
      "63 : 12\n",
      "17 : 10\n",
      "53 : 14\n",
      "5 : 17\n",
      "10 : 20\n",
      "91 : 7\n",
      "67 : 6\n",
      "97 : 16\n",
      "88 : 11\n",
      "5 : 17\n",
      "11 : 8\n",
      "31 : 10\n",
      "46 : 9\n",
      "72 : 9\n",
      "28 : 8\n",
      "69 : 12\n",
      "90 : 14\n",
      "34 : 5\n",
      "38 : 20\n",
      "23 : 11\n",
      "55 : 5\n",
      "76 : 16\n",
      "41 : 9\n",
      "24 : 19\n",
      "15 : 11\n",
      "24 : 19\n",
      "68 : 10\n",
      "22 : 8\n",
      "89 : 14\n",
      "35 : 7\n",
      "36 : 8\n",
      "38 : 20\n",
      "76 : 16\n",
      "50 : 10\n",
      "52 : 9\n",
      "5 : 17\n",
      "98 : 8\n",
      "16 : 11\n",
      "19 : 6\n",
      "38 : 20\n",
      "93 : 17\n",
      "49 : 9\n",
      "93 : 17\n",
      "38 : 20\n",
      "69 : 12\n",
      "80 : 9\n",
      "27 : 15\n",
      "68 : 10\n",
      "39 : 11\n",
      "10 : 20\n",
      "36 : 8\n",
      "43 : 17\n",
      "23 : 11\n",
      "39 : 11\n",
      "71 : 13\n",
      "95 : 14\n",
      "63 : 12\n",
      "83 : 17\n",
      "1 : 11\n",
      "18 : 4\n",
      "49 : 9\n",
      "30 : 16\n",
      "23 : 11\n",
      "2 : 15\n",
      "14 : 13\n",
      "97 : 16\n",
      "97 : 16\n",
      "36 : 8\n",
      "75 : 11\n",
      "97 : 16\n",
      "0 : 8\n",
      "23 : 11\n",
      "7 : 5\n",
      "66 : 10\n",
      "77 : 8\n",
      "29 : 10\n",
      "30 : 16\n",
      "47 : 9\n",
      "34 : 5\n",
      "27 : 15\n",
      "11 : 8\n",
      "10 : 20\n",
      "71 : 13\n",
      "80 : 9\n",
      "95 : 14\n",
      "59 : 9\n",
      "14 : 13\n",
      "46 : 9\n",
      "94 : 14\n",
      "48 : 8\n",
      "5 : 17\n",
      "21 : 16\n",
      "12 : 4\n",
      "83 : 17\n",
      "65 : 10\n",
      "5 : 17\n",
      "43 : 17\n",
      "98 : 8\n",
      "81 : 7\n",
      "51 : 13\n",
      "41 : 9\n",
      "72 : 9\n",
      "26 : 15\n",
      "21 : 16\n",
      "93 : 17\n",
      "95 : 14\n",
      "75 : 11\n",
      "32 : 9\n",
      "25 : 8\n",
      "80 : 9\n",
      "27 : 15\n",
      "85 : 6\n",
      "93 : 17\n",
      "93 : 17\n",
      "92 : 11\n",
      "4 : 10\n",
      "2 : 15\n",
      "95 : 14\n",
      "43 : 17\n",
      "54 : 10\n",
      "96 : 7\n",
      "59 : 9\n",
      "45 : 15\n",
      "59 : 9\n",
      "68 : 10\n",
      "20 : 9\n",
      "25 : 8\n",
      "81 : 7\n",
      "69 : 12\n",
      "51 : 13\n",
      "93 : 17\n",
      "86 : 5\n",
      "76 : 16\n",
      "43 : 17\n",
      "32 : 9\n",
      "24 : 19\n",
      "43 : 17\n",
      "41 : 9\n",
      "43 : 17\n",
      "12 : 4\n",
      "90 : 14\n",
      "26 : 15\n",
      "90 : 14\n",
      "61 : 11\n",
      "38 : 20\n",
      "53 : 14\n",
      "94 : 14\n",
      "94 : 14\n",
      "29 : 10\n",
      "52 : 9\n",
      "36 : 8\n",
      "64 : 6\n",
      "29 : 10\n",
      "42 : 5\n",
      "14 : 13\n",
      "92 : 11\n",
      "30 : 16\n",
      "81 : 7\n",
      "96 : 7\n",
      "97 : 16\n",
      "14 : 13\n",
      "94 : 14\n",
      "93 : 17\n",
      "18 : 4\n",
      "10 : 20\n",
      "2 : 15\n",
      "78 : 7\n",
      "13 : 13\n",
      "20 : 9\n",
      "30 : 16\n",
      "3 : 9\n",
      "65 : 10\n",
      "26 : 15\n",
      "79 : 9\n",
      "78 : 7\n",
      "64 : 6\n",
      "25 : 8\n",
      "5 : 17\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "57 : 8\n",
      "74 : 8\n",
      "24 : 19\n",
      "71 : 13\n",
      "10 : 20\n",
      "39 : 11\n",
      "15 : 11\n",
      "5 : 17\n",
      "96 : 7\n",
      "88 : 11\n",
      "49 : 9\n",
      "12 : 4\n",
      "76 : 16\n",
      "38 : 20\n",
      "29 : 10\n",
      "96 : 7\n",
      "16 : 11\n",
      "44 : 9\n",
      "60 : 8\n",
      "21 : 16\n",
      "24 : 19\n",
      "89 : 14\n",
      "29 : 10\n",
      "7 : 5\n",
      "30 : 16\n",
      "55 : 5\n",
      "85 : 6\n",
      "100 : 8\n",
      "65 : 10\n",
      "97 : 16\n",
      "41 : 9\n",
      "71 : 13\n",
      "43 : 17\n",
      "15 : 11\n",
      "24 : 19\n",
      "0 : 8\n",
      "91 : 7\n",
      "80 : 9\n",
      "69 : 12\n",
      "100 : 8\n",
      "90 : 14\n",
      "54 : 10\n",
      "71 : 13\n",
      "71 : 13\n",
      "98 : 8\n"
     ]
    }
   ],
   "source": [
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入键1\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "d = {1:'a',2:'b',3:'c',4:'d'}  \n",
    "v=input('请输入键')\n",
    "v=eval(v)\n",
    "print(d.get(v,'您输入的建不存在！'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[8, 37, 54, 60, 60, 62, 76, 86, 92, 97, 86, 82, 75, 73, 39, 24, 24, 12, 6, 5]\n"
     ]
    }
   ],
   "source": [
    "import random               \n",
    "x=[random.randint(1,100)for i in range(20)]\n",
    "a=sorted(x[:10])\n",
    "b=sorted(x[10:],reverse=True)\n",
    "x=a+b\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
